home *** CD-ROM | disk | FTP | other *** search
/ Varios Español / Varios Español.iso / DBASE5 / CUA_SAMP.ZIP / CHKUNIQ.PRG < prev    next >
Text File  |  1994-10-12  |  4KB  |  143 lines

  1.  
  2. FUNCTION ChkUniq
  3. PARAMETERS pThis, pForm
  4. *----------------------------------------------------------------------------
  5. * NAME
  6. *   ChkUniq() - Check field value for uniqueness
  7. *
  8. *----------------------------------------------------------------------------
  9. #include "talkoff.hdb"
  10.     PRIVATE lAppend, cMaster, nRecno, cOrder, entryKey, cKeyTag
  11.     PRIVATE lKeyViol, cKey, lDelete, nSeekRec, lGoTo
  12.     PRIVATE cIntlMess, cIntlTitle, cIntlYes, cIntlNo
  13.  
  14.     cIntlMess  = [Violación de clave primaria. ¿Desea ir al registro existente?]
  15.     cIntlTitle = [Información]
  16.     cIntlYes   = [~S~í]
  17.     cIntlNo    = [~N~o]
  18.  
  19.     *--------------------------------------------------------------
  20.     *-- Select the Form master and set order to the master key tag.
  21.     *--------------------------------------------------------------
  22.     cMaster = pForm.CurrMast
  23.     SELECT ( m->cMaster )
  24.     IF EOF()
  25.         lAppend = .T.
  26.     ELSE
  27.         lAppend = .F.
  28.     ENDIF
  29.     nSeekRec = 0
  30.     nRecno = RECNO()
  31.     cOrder = ORDER()
  32.     cKeyTag = pThis.KeyTag
  33.     entryKey = pThis.Value
  34.     IF m->cOrder <> m->cKeyTag
  35.         SET ORDER TO ( m->cKeyTag )
  36.     ENDIF
  37.  
  38.     lDelete = SET( "DELETE" ) = "ON"
  39.     SET DELETE OFF
  40.  
  41.     lKeyViol = .F.                      && Assume no key violation
  42.  
  43.     IF SEEK( m->entryKey )
  44.         nSeekRec = RECNO()
  45.         IF .NOT. m->lAppend
  46.             IF m->nSeekRec <> m->nRecno
  47.                 lKeyViol = .T.          && Key violation here
  48.             ELSE
  49.                 SKIP
  50.                 cKey = KEY()
  51.                 IF entryKey = EVAL( m->cKey )
  52.                     lKeyViol = .T.      && Key violation here
  53.                 ENDIF
  54.             ENDIF
  55.         ELSE
  56.             lKeyViol = .T.              && Key violation here
  57.         ENDIF
  58.     ENDIF
  59.  
  60.     IF lDelete
  61.         SET DELETE ON
  62.     ENDIF
  63.  
  64.     *--------------------------------------------------
  65.     *-- Display the key violation error if it occurred.
  66.     *--------------------------------------------------
  67.     lGoTo = .F.
  68.     IF lKeyViol
  69.         #include "errmsg.hdb"
  70.         dB5___EMsg.Message = m->cIntlMess
  71.         dB5___EMsg.BoxTitle = m->cIntlTitle
  72.         dB5___EMsg.OkText = m->cIntlYes
  73.         dB5___EMsg.CancelBtn = .T.
  74.         dB5___EMsg.CancelText = m->cIntlNo
  75.         DO ErrMsg WITH dB5___EMsg
  76.         lGoTo = dB5___EMsg.OkChosen
  77.         lVoid = dB5___EMsg.Release()
  78.         RELEASE dB5___EMsg
  79.  
  80.         IF lGoTo
  81.             lKeyViol = .F.              && Reset value for proper exit
  82.             GO nSeekRec
  83.             lVoid = pForm.Refresh()      && Display the new values
  84.             pForm.AddingRec = .F.
  85.             SELECT ( pForm.CurrMast )
  86.  
  87.             *-----------------------------------------
  88.             *-- If there are no lookups, bail out now.
  89.             *-----------------------------------------
  90.             IF TYPE( "pForm.Scan4Look" ) # "N"
  91.                 #include "talkon.hdb"
  92.                 RETURN .T.
  93.             ENDIF
  94.  
  95.             *-----------------------------------------------------------
  96.             *-- For Each field that has a lookup, call LookRef to update
  97.             *-- the value of the look fields.
  98.             *-----------------------------------------------------------
  99.             oF = pForm.First
  100.             oC = m->oF
  101.             DO WHILE .T.
  102.                 IF oC.ClassName = "ENTRYFIELD"
  103.                     IF TYPE( "oC.LookTag" ) = "C"
  104.                         SELECT (oC.LookAlias)
  105.                         cKey = oc.DataLink
  106.                         SEEK EVAL( m->cKey )
  107.                         DO LookRef WITH oC.LookAlias, m->oC
  108.                     ENDIF
  109.                 ENDIF
  110.                 oC = oC.After
  111.                 IF oC = m->oF
  112.                     EXIT
  113.                 ENDIF
  114.             ENDDO
  115.  
  116.             IF TYPE( "pForm.DetExist" ) = "L" .AND. pForm.DetExist
  117.                 DO UpDetail WITH pForm
  118.             ENDIF
  119.         ENDIF
  120.     ENDIF
  121.  
  122.     IF .NOT. m->lGoTo
  123.         IF m->cOrder <> m->cKeyTag
  124.             SET ORDER TO ( m->cOrder )
  125.         ENDIF
  126.         IF m->lAppend
  127.             GO BOTTOM
  128.             IF .NOT. EOF()
  129.                 SKIP
  130.             ENDIF
  131.         ELSE
  132.             GO m->nRecno
  133.         ENDIF
  134.     ENDIF
  135.  
  136. #include "talkon.hdb"
  137. RETURN  .NOT. m->lKeyViol
  138. *-- EOF: ChkUniq()
  139.  
  140.  
  141.  
  142.  
  143.